package struct.login
{
	import collection.DataCollection;
	
	import flash.events.MouseEvent;
	
	import struct.gameinfo.GameInfoModule;
	import struct.help.HelpModule;
	import struct.login.ui.LoginUI;
	import struct.scene.SceneModule;
	
	import utils.Util;

	public class LoginModule
	{
		protected static var _instance:LoginModule;
		private var base:LoginUI;
		public function LoginModule()
		{
			base = new LoginUI();
		}
		
		public static function getInstance():LoginModule
		{
			if (!_instance)
			{
				_instance = new LoginModule();
			}
			return _instance;
		}
		public function startUp():void
		{
			Main.application.uiLayer.addChild(base);
			//如果有记录用户名， 启动时记录下
			if(Util.trim(DataCollection.userName) != '')base.txtName.text = DataCollection.userName;
			
			base.btnStart.addEventListener(MouseEvent.CLICK, onClick);
			base.btnHelp.addEventListener(MouseEvent.CLICK, onClick);
			base.btnHttp.addEventListener(MouseEvent.CLICK, onClick);
		}
		
		protected function onClick(event:MouseEvent):void
		{
			switch(event.target)
			{
				case base.btnStart:
					DataCollection.userName = Util.trim(base.txtName.text);
					SceneModule.getInstance().setMission(DataCollection.mission); //游戏界面
					GameInfoModule.getInstance().startUp(); //游戏信息揭秘那
					closeModule(); //关闭登陆界面
					
					break;
				case base.btnHelp:
					HelpModule.getInstance().startUp();
					break;
				case base.btnHttp:
					
					break;
			}
		}
		
		/**
		 * 
		 * 
		 */		
		public function closeModule():void
		{
			Main.application.uiLayer.removeChild(base);
			base.btnStart.removeEventListener(MouseEvent.CLICK, onClick);
			base.btnHelp.removeEventListener(MouseEvent.CLICK, onClick);
			base.btnHttp.removeEventListener(MouseEvent.CLICK, onClick);
		}
		
		public function dispose():void
		{
			
		}
	}
}